#include "common.h"
#include <stdint.h>
#include <stdio.h>
#include <cstring>
#include <string>
#include <unordered_map>

//
// Created by Administrator on 2023/3/20.
//
int lengthOfLongestSubstring(std::string s){
    std::unordered_map<char, int> window;

    int left = 0, right = 0;
    int res = 0;
    while(right < s.size()){
        char c = s[right];
        right++;
        window[c]++;

        //判断左侧窗口是否需要收缩
        while(window[c] > 1){
            char d = s[left];
            left++;
            //进行窗口内数据的一系列更新
            window[d]--;
        }
        //在这里更新答案
        res = std::max(res, right - left);
    }
    return res;
}

int main(){
    //pat_1001_callatz();
    //printSumPinyin();
    int count = 0;
    count = lengthOfLongestSubstring("bbbbb");
    printf("bbbbb result :%d\n",count);

    count = lengthOfLongestSubstring("abcabcbb");
    printf("abcabcbb result :%d\n",count);

    count = lengthOfLongestSubstring("pwwkew");
    printf("pwwkew result :%d\n",count);
    return 0;
}
